
package bbchess.dialogs;

import bbchess.MainGui;
import java.awt.Point;

/**
 * ChessDialog is the closest class to JDialog, and all Chess Dialogs extend
 * it. All common functionality is implemented here and passed to child classes.
 * @author tyler
 */
public class ChessDialog extends javax.swing.JDialog {

    // Declare variables
    private MainGui mainGui;
    private boolean disableScreen;

    public ChessDialog(java.awt.Frame parent, boolean modal, boolean disableScreen) {
        super(parent, modal);

        mainGui = (MainGui) parent;
        this.disableScreen = disableScreen;

        centerFrameToGui();
    }

    @Override
    public void setVisible(boolean choice) {
        // if true
        if (choice) {
            centerFrameToGui();
        }

        super.setVisible(choice);
        if (disableScreen) {
            mainGui.glassPane.setScreenDisabled(true);
        }
    }

    @Override
    public void dispose() {
        this.setVisible(false);
        if (disableScreen) {
            mainGui.glassPane.setScreenDisabled(false);
        }
    }

    private void centerFrameToGui() {
        Point mainCenter = mainGui.getCenter();
        setLocation(new Point((int) mainCenter.getX() - getWidth()/2, (int) mainCenter.getY() - getHeight()/2));
    }

    public MainGui getMainGui() {
        return mainGui;
    }

}
